#include <iostream>
#include <vector>
using namespace std;
class Solution
{
public:
    vector<int> *a;
    Solution(vector<int> &nums)
    {
        a = &nums;
    }

    int pick(int target)
    {
        int index = -1; //最终返回的下标
        int n = 0;      //找到的第n个数
        for (int i = 0; i < a->size(); i++)
            if (a->at(i) == target)
            {
                n++;
                if (rand() % n == 0)
                {
                    index = i;
                }
            }
        return index;
    }
};
int main()
{
    vector<int> v{4, -2, -3, 4, 1};
    Solution *s = new Solution(v);
    int ans = s->pick(4);
    cout << ans << endl;
    return 0;
}